<template>
  <div>
    <el-form ref="EditForm" :model="EditForm" label-width="80px" style="width:84%;" status-icon>
      <el-form-item label="版块号">
        <el-input v-model="EditForm.collegeId" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="版块名">
        <el-input v-model="EditForm.collegeName"></el-input>
      </el-form-item>
      <el-form-item label="版主">
        <el-input v-model="EditForm.moderator"></el-input>
      </el-form-item>
    </el-form>
    <!--按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="edit()">保存</el-button>
      <el-button @click="reset()">重置</el-button>
    </span>
  </div>
</template>
<script>
export default {
  props: ['scope'],
  data() {
    return {
      EditForm: {
        collegeId: '',
        collegeName: '',
        moderator: ''
      }
    }
  },
  created() {
    this.comm.assignmentObject(this.scope, this.EditForm)
  },
  methods: {
    // 保存
    async edit() {
      // console.log(this.EditForm)
      // console.log(this.scope)
      var d
      await this.comm.compareObject(this.scope, this.EditForm).then(async data => {
        console.log(data)
        if (JSON.stringify(data) === '{}') {
          return (d = 1)
        }
        const res = await this.$http.post('/editcollege', {
          collegeId: this.scope.collegeId,
          edit: data
        })
        if (res.meta.status !== 200) {
          return this.$Message.error('修改失败')
        }
        this.$Message.success('修改成功')
        this.$emit('editSuccess', this.EditForm)
      })
      if (d) {
        return
      }

      // this.$router.go(0)
    },
    // 重置
    reset() {
      this.comm.assignmentObject(this.scope, this.EditForm)
    }
  }
}
</script>
<style lang="less" scoped>
.dialog-footer {
  display: flex;
  justify-items: center;
  .el-button {
    margin: 0 auto 10px;
  }
}
</style>
